<?php
ini_set('memory_limit', '1024M');
$file = isset($argv[1]) ? $argv[1] : '';
if (empty($file)) {
        echo "please input file \n";
}

if (!is_file($file)) {
        echo "no such file \n";
}

$file = fopen($file, 'r');

$con = mysql_connect("10.0.11.142", "yongche", "yongche");
if (!$con) {
    die("counldn't connect db: " .mysql_error());
}
mysql_select_db("yc_car_master_stat", $con);
//$statTime = "20161015";
$statTime = $argv[2];
echo "the stat time is " .$statTime ."\n";
while($row = fgets($file)) {
    $data = explode(" ", trim($row));
    //var_dump($data);
    //echo "the count is {$data[0]} and the IMEI is {$data[1]}\n";
    $ret = mysql_query("INSERT into user_agent_device_cnt (imei, visit_count, stat_time) values ('{$data[1]}', {$data[0]}, $statTime)");
//    print_r($data);
}
mysql_close($con);
